//
//  HCHK_iphoneAppDelegate.m
//  HCHK_iphone
//
//  Created by yilong zhang on 11-12-7.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "HCHK_iphoneAppDelegate.h"

@implementation HCHK_iphoneAppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    
    /*
     size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
    free(machine);
    NSLog(@"%@", platform);
     
     if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";  
     if ([platform isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";  
     if ([platform isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";  
     if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";  
     if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";  
     if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";  
     if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";  
     if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";  
     if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";  
     if ([platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"])        
     return @"iPhone Simulator";  
     return platform;  
     */
    
    [application setStatusBarHidden:YES];
    application.applicationSupportsShakeToEdit = YES;
    
    //注册推送服务
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert];
    
    [[CDBManager ScheduledShareInstance] CreateDB];
    [[AppConfig DefaultAppConfig] CreateAppDirectory];
    
    //添加RootCtrlManager
    CGPoint point = [CRootCtrlManager DefaultRootCtrl].view.center;
    [CRootCtrlManager DefaultRootCtrl].view.center = CGPointMake(point.x, point.y);
    [self.window addSubview:[CRootCtrlManager DefaultRootCtrl].view];
    [AppConfig DefaultAppConfig].m_DeliciousCtrl = [CRootCtrlManager DefaultRootCtrl];
    
    [self.window makeKeyAndVisible];
    
    /*NSString *title = @"title";  
    float latitude = 35.4634;  
    float longitude = 9.43425;  
    int zoom = 13;  
    NSString *stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@@%1.6f,%1.6f&z=%d", title, latitude, longitude, zoom];  
    NSURL *url = [NSURL URLWithString:stringURL]; */ 
        
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
    [[NSNotificationCenter defaultCenter] postNotificationName:MSG_APP_BACKUP object:nil];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
     */
}

//推送
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSLog(@"注册推送服务成功");
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    NSLog(@"注册推送服务出错__%@", error);
}

-(void)LaunchingPushNotification:(NSNotification*)notification
{
    NSLog(@"推送通知已经到达");
}

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"收到推送通知");
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
    [[NSNotificationCenter defaultCenter] postNotificationName:MSG_APP_ACTIVE object:nil];
}

//buffernone
-(void)GetBufferNone:(NSNotification*)notification
{
    UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"本地没有可用数据，不能使用。" delegate:self cancelButtonTitle:@"退出" otherButtonTitles:nil];
    alter.tag = 2;
    [alter show];
    [alter autorelease];
}
/*
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (1 == alertView.tag)
    {
        if (0 == buttonIndex)
        {
            NSLog(@"<========程序退出========>");
            exit(0);
        }
        else if (1 == buttonIndex)
        {
            //m_LoadTitle.text = @"正在获取数据...";
            
            //[self performSelector:@selector(LoadDatas) withObject:self afterDelay:1];
            [[CRootCtrlManager DefaultRootCtrl] LoadDatas];
        }
        else {;}
    }
}
*/
- (void)applicationWillTerminate:(UIApplication *)application
{
    /*
     Called when the application is about to terminate.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
}

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

@end
